package com.bms.admin.base.log.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bms.admin.base.log.entity.Log;
import com.bms.admin.base.log.entity.LoginLog;
import com.bms.admin.base.log.service.ILogService;
import com.bms.admin.base.log.service.ILoginLogService;
import com.bms.auth.annotation.RequiresPermissions;
import com.bms.common.base.common.bean.Result;
import com.bms.common.base.web.BaseController;
import com.feilong.core.Validator;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 系统日志  前端控制器
 * </p>
 *
 * @author xj
 * @since 2018-08-09
 */
@RestController
@RequestMapping("log")
@Api(value="Log-Api",tags="操作日志管理")
public class LogController extends BaseController {

	@Autowired
	private ILogService logService;
	
	@Autowired
	private ILoginLogService loginService;
	
	@ApiOperation("获取用户操作日志列表")
	@GetMapping("logList")
	@RequiresPermissions("log:logList")
    public Result logList(@RequestParam(defaultValue = "1",required=false)Integer pageNum,
    				   @RequestParam(defaultValue = "20",required=false)Integer pageSize,
    				   String username) {
		return json(logService.selectPage(new Page<Log>(pageNum,pageSize),new EntityWrapper<Log>().like(Validator.isNotNullOrEmpty(username),"username", username).orderBy("create_time", false)));
    }
	
	
	@ApiOperation("获取用户登录日志列表")
	@GetMapping("loginList")
	@RequiresPermissions("log:loginList")
    public Result loginList(@RequestParam(defaultValue = "1",required=false)Integer pageNum,
    				   @RequestParam(defaultValue = "20",required=false)Integer pageSize,
    				   String username) {
		return json(loginService.selectPage(new Page<LoginLog>(pageNum,pageSize),new EntityWrapper<LoginLog>().like(Validator.isNotNullOrEmpty(username),"username", username).orderBy("create_time", false)));
    }
}
